package com.huike.clues.service.impl;
import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;

import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 *
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Autowired
    private TbClueMapper tbClueMapper;

    /**
     * 查询线索跟进记录列表
     *
     * @param clueId
     * @return
     */
    @Override
    public List<TbClueTrackRecord> selectTbClueTrackRecordById(Long clueId) {
        return tbClueTrackRecordMapper.selectTbClueTrackRecordById(clueId);
    }

   /* @Override
    public List<TbClueTrackRecord> selectTbClueTrackRecord(TbClueTrackRecord tbClueTrackRecord) {
        return tbClueTrackRecordMapper.selectTbClueTrackRecord(tbClueTrackRecord);
    }*/

    @Override
    public int add(ClueTrackRecordVo tbClueTrackRecord) {
        //先添加进入线索表中
        TbClue tbClue = new TbClue();
        tbClue.setId(tbClueTrackRecord.getClueId());
        tbClue.setSubject(tbClueTrackRecord.getSubject());
        tbClue.setLevel(tbClueTrackRecord.getLevel());
        tbClue.setName(tbClueTrackRecord.getName());
        tbClue.setSex(tbClueTrackRecord.getSex());
        tbClue.setWeixin(tbClueTrackRecord.getWeixin());
        tbClue.setQq(tbClueTrackRecord.getQq());
        tbClue.setAge(tbClueTrackRecord.getAge());
        tbClueMapper.insertTbClue(tbClue);
        //添加入线索跟进表中
        TbClueTrackRecord tbClueTrackRecord1 = new TbClueTrackRecord();
        tbClueTrackRecord1.setClueId(tbClueTrackRecord.getClueId());
        tbClueTrackRecord1.setCreateBy(SecurityUtils.getUsername());
        tbClueTrackRecord1.setSubject(tbClueTrackRecord.getSubject());
        tbClueTrackRecord1.setRecord(tbClueTrackRecord.getRecord());
        tbClueTrackRecord1.setLevel(tbClueTrackRecord.getLevel());
        Date now = DateUtils.getNowDate();
        tbClueTrackRecord1.setCreateTime(now);
        tbClueTrackRecord1.setType(tbClueTrackRecord.getType());
        tbClueTrackRecord1.setFalseReason(tbClueTrackRecord.getFalseReason());
        tbClueTrackRecord1.setNextTime(tbClueTrackRecord.getNextTime());
        tbClueTrackRecordMapper.add(tbClueTrackRecord1);
        return 1;
    }


}

